<template>
  <view class="container">
    <view class="header">
      <text class="title">学生列表</text>
    </view>

    <view class="student-list">
      <view 
        v-for="student in students" 
        :key="student.id" 
        class="student-card"
        @click="editStudent(student.id)"
      >
        <view class="info">
          <text class="name">{{ student.name }}</text>
          <text class="details">{{ student.age }}岁 · {{ student.gender }} · {{ student.major }}</text>
        </view>
        <uni-icons type="arrowright" size="20" color="#999"></uni-icons>
      </view>
      
      <view v-if="students.length === 0" class="empty">
        <uni-icons type="info" size="40" color="#999"></uni-icons>
        <text>暂无学生数据</text>
      </view>
    </view>

    <button class="add-btn" @click="addStudent">添加学生</button>
  </view>
</template>

<script>
import mockData from '@/static/mock-data.js';

export default {
  data() {
    return {
      students: []
    };
  },
  onShow() {
    this.loadStudents();
  },
  methods: {
    loadStudents() {
      this.students = mockData.getStudents();
    },
    editStudent(id) {
      uni.navigateTo({
        url: `/pages/edit/edit?id=${id}`
      });
    },
    addStudent() {
      uni.navigateTo({
        url: '/pages/add/add'
      });
    }
  }
};
</script>

<style>
.container {
  padding: 30rpx;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.header {
  padding: 30rpx 0;
  border-bottom: 1rpx solid #eee;
  margin-bottom: 30rpx;
}

.title {
  font-size: 40rpx;
  font-weight: bold;
  color: #333;
}

.student-list {
  margin-bottom: 120rpx;
}

.student-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 30rpx;
  margin-bottom: 20rpx;
  background-color: white;
  border-radius: 16rpx;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
}

.info {
  flex: 1;
}

.name {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 10rpx;
  display: block;
}

.details {
  font-size: 28rpx;
  color: #888;
  display: block;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100rpx 0;
  color: #999;
  font-size: 28rpx;
}

.add-btn {
  position: fixed;
  bottom: 50rpx;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 90rpx;
  line-height: 90rpx;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  color: white;
  font-size: 36rpx;
  border-radius: 45rpx;
}
</style>